package com.lingshi.shopping_manager_api.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import com.lingshi.shopping_manager_api.interceptor.CheckLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录（认证）检查拦截器
        registry.addInterceptor(checkLoginInterceptor)
                .addPathPatterns("/**") //所有请求都拦截
                .excludePathPatterns("/admin/login","/ws","/error");//放行登录请求
        //添加sa-token的授权 拦截器
        registry.addInterceptor(new SaInterceptor())
                .addPathPatterns("/**");//所有的资源访问都需要权限
    }
}
